import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import {list as projectList} from '../project/WmProject.api'
import {list as clientList} from '../client/WmClient.api'
import { render } from '/@/utils/common/renderUtils';
import { useUserStore } from '/@/store/modules/user';
import dayjs from "dayjs";
import {defHttp} from "@/utils/http/axios";
const userStore = useUserStore()
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '合同名称',
    align:"center",
    dataIndex: 'name',
    width:180,
    resizable: true,
    ellipsis:true
   },
   {
    title: '负责人',
    align:"center",
    dataIndex: 'chargeBy_dictText',
    defaultHidden:true
   },
   {
    title: '合同类型',
    align:"center",
    width:100,
    dataIndex: 'type_dictText'
   },
   {
    title: '所属项目',
    align:"center",
    dataIndex: 'wmProjectId_dictText',
    width:150,
    resizable: true,
    ellipsis:true
   },
   {
    title: '签订日期',
    align:"center",
    dataIndex: 'signDate',
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
    width:100,
    resizable: true,
    ellipsis:true
   },
   {
    title: '甲方合同编号',
    align:"center",
    dataIndex: 'clientContractNo',
    width:160,
    resizable: true,
    ellipsis:true
   },
   {
    title: '乙方合同编号',
    align:"center",
    dataIndex: 'code',
    width:160,
    resizable: true,
    ellipsis:true
   },
   {
    title: '甲方单位',
    align:"center",
    dataIndex: 'wmClientId_dictText',
    width:180,
    resizable: true,
    ellipsis:true
   },
   {
    title: '乙方单位',
    align:"center",
    dataIndex: 'wmVendorId_dictText',
    width:180,
    resizable: true,
    ellipsis:true
   },

  //  {
  //   title: '进度权重',
  //   align:"center",
  //   dataIndex: 'weight'
  //  },
   {
    title: '联系电话',
    align:"center",
    dataIndex: 'phone',
    defaultHidden:true
   },
   {
    title: '进度',
    align:"center",
    dataIndex: 'progress',
    customRender:({text})=>{
      return render.renderProcess((text))
    }
   },
   {
    title: '计划开始时间',
    align:"center",
    width:120,
    dataIndex: 'planBeginTime'
   },
   {
    title: '计划完成时间',
    align:"center",
    width:120,
    dataIndex: 'planEndTime'
   },
   {
    title: '实际开始时间',
    align:"center",
    dataIndex: 'factBeginTime',
    defaultHidden:true
   },
   {
    title: '实际完成时间',
    align:"center",
    dataIndex: 'factEndTime',
    defaultHidden:true
   },
   {
    title: '不含税金额',
    align:"center",
    dataIndex: 'noTaxMoney',
    defaultHidden:true
   },
   {
    title: '单价',
    align:"center",
    dataIndex: 'price',
    defaultHidden:true
   },
   {
    title: '税额',
    align:"center",
    dataIndex: 'tax',
    defaultHidden:true
   },
   {
    title: '合计金额',
    align:"center",
    dataIndex: 'money',
    defaultHidden:true
   },
   {
     title:'部门',
     align:'center',
     width:100,
     dataIndex:'sysOrgCode_dictText'
   },
   {
    title: '状态',
    align:"center",
    fixed:'right',
    width:120,
    dataIndex: 'status_dictText'
   },
   {
    title: '备注',
    align:"center",
    dataIndex: 'remark',
    defaultHidden:true
   },
];

export const projInnerContrCols:BasicColumn[]=[
  {
    title: '合同名称',
    align:"center",
    dataIndex: 'name',
    width:180,
    resizable: true,
    ellipsis:true
   },
   {
    title: '负责人',
    align:"center",
    dataIndex: 'chargeBy_dictText',
    defaultHidden:true
   },
   {
    title: '合同类型',
    align:"center",
    width:100,
    dataIndex: 'type_dictText'
   },
   {
    title: '所属项目',
    align:"center",
    dataIndex: 'wmProjectId_dictText',
    width:150,
    resizable: true,
    ellipsis:true
   },
   {
    title: '签订日期',
    align:"center",
    dataIndex: 'signDate',
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
    width:100,
    resizable: true,
    ellipsis:true
   },
   {
    title: '甲方合同编号',
    align:"center",
    dataIndex: 'clientContractNo',
    width:160,
    resizable: true,
    ellipsis:true
   },
   {
    title: '乙方合同编号',
    align:"center",
    dataIndex: 'code',
    width:160,
    resizable: true,
    ellipsis:true
   },
   {
    title: '甲方单位',
    align:"center",
    dataIndex: 'wmClientId_dictText',
    width:180,
    resizable: true,
    ellipsis:true
   },
   {
    title: '乙方单位',
    align:"center",
    dataIndex: 'wmVendorId_dictText',
    width:180,
    resizable: true,
    ellipsis:true
   },

  //  {
  //   title: '进度权重',
  //   align:"center",
  //   dataIndex: 'weight'
  //  },
   {
    title: '联系电话',
    align:"center",
    dataIndex: 'phone',
    defaultHidden:true
   },
   {
    title: '进度',
    align:"center",
    dataIndex: 'progress',
    customRender:({text})=>{
      return render.renderProcess((text))
    }
   },
   {
    title: '计划开始时间',
    align:"center",
    width:120,
    dataIndex: 'planBeginTime'
   },
   {
    title: '计划完成时间',
    align:"center",
    width:120,
    dataIndex: 'planEndTime'
   },
   {
    title: '实际开始时间',
    align:"center",
    dataIndex: 'factBeginTime',
    defaultHidden:true
   },
   {
    title: '实际完成时间',
    align:"center",
    dataIndex: 'factEndTime',
    defaultHidden:true
   },
   {
    title: '不含税金额',
    align:"center",
    dataIndex: 'noTaxMoney',
    defaultHidden:true
   },
   {
    title: '单价',
    align:"center",
    dataIndex: 'price',
    defaultHidden:true
   },
   {
    title: '税额',
    align:"center",
    dataIndex: 'tax',
    defaultHidden:true
   },
   {
    title: '合计金额',
    align:"center",
    dataIndex: 'money',
    defaultHidden:true
   },
   {
     title:'部门',
     align:'center',
     width:100,
     dataIndex:'sysOrgCode_dictText'
   },
   {
    title: '状态',
    align:"center",
    fixed:'right',
    dataIndex: 'status_dictText',
    defaultHidden:false
   },
   {
    title: '备注',
    align:"center",
    dataIndex: 'remark',
    defaultHidden:true
   }
]

export const imptTreeColumns:BasicColumn[]=[
  {
    title: '名称',
    align:"left",
    dataIndex: 'title'
   },
  {
    title:'编码',
    align:"center",
    dataIndex:'code'
  },
  {
    title: '层级',
    align:"center",
    dataIndex: 'level',
    defaultHidden:true
   },
  {
    title: '产品性质',
    align:"center",
    dataIndex: 'taskType',
    customRender:({text})=>{
      return render.renderDict(text,'task_type')
    }
   },
  {
    title: '物料/产品',
    align:"center",
    dataIndex: 'itemOrProduct',
    defaultHidden:true,
    customRender:({text})=>{
      return render.renderDict(text,'item_or_product')
    }
   },
  {
    title: '数量',
    align:"center",
    dataIndex: 'quantity'
   },
  {
    title:'单位',
    align:'center',
    dataIndex:'unitOfMeasure',
    customRender:({text}) =>{
      return render.renderDict(text, 'unit_of_measure');
    }
  },
  {
    title: '规格',
    align:"center",
    dataIndex: 'specification'
   }

]

export const bomListColumns:BasicColumn[]=[
  {
    title: '编码',
    align:"center",
    dataIndex: 'code'
   },
  {
    title: '名称',
    align:"center",
    dataIndex: 'name'
   },
  {
    title: '单位',
    align:"center",
    dataIndex: 'unitOfMeasure',
    customRender: ({ text }) => {
      return render.renderDict(text, 'unit_of_measure');
    },
   },
  {
    title: '需求数量',
    align:"center",
    dataIndex: 'needNum'
   },
  // {
  //   title: '库存数量',
  //   align:"center",
  //   dataIndex: 'childProductName'
  //  },
  {
    title: '采购数量',
    align:"center",
    dataIndex: 'purchaseNum'
   },
  {
    title: '报废数量',
    align:"center",
    dataIndex: 'wasteNum'
   },
  {
    title: '退还数量',
    align:"center",
    dataIndex: 'returnNum'
   },
  // {
  //   title: '技改数量',
  //   align:"center",
  //   dataIndex: 'childProductName'
  //  },
  {
    title: '采购时间',
    align:"center",
    dataIndex: 'purchaseTime'
   },
  {
    title: '到货时间',
    align:"center",
    dataIndex: 'arriveTime'
   },
  {
    title: '规格型号',
    align:"center",
    dataIndex: 'specification'
   },
  // {
  //   title: '品牌',
  //   align:"center",
  //   dataIndex: 'childProductName'
  //  },
  // {
  //   title: '所属设备',
  //   align:"center",
  //   dataIndex: 'childProductName'
  //  },
]


export const bomMapColumns:BasicColumn[]=[
  {
    title: '合同号',
    align:"center",
    dataIndex: 'wmContractId'
   },
  {
    title: '客户名称',
    align:"center",
    dataIndex: 'customerName'
   },
  {
    title: '子项设备/材料名称',
    align:"center",
    dataIndex: 'childProductName'
   },
  {
    title: '销售产品编码',
    align:"center",
    dataIndex: 'productCode'
   },
  {
    title: '销售产品名称',
    align:"center",
    dataIndex: 'productName'
   },
  {
    title: '规格',
    align:"center",
    dataIndex: 'specification'
   },
  {
    title: '单位',
    align:"center",
    dataIndex: 'unitOfMeasure'
   },
  {
    title: '数量',
    align:"center",
    dataIndex: 'quantity'
   },
  {
    title: '计划号',
    align:"center",
    dataIndex: 'wmTaskbookId'
   }
]

export const imptProductColumns:BasicColumn[]=[
  {
    title: '编码',
    align:"center",
    dataIndex: 'code'
   },
  {
    title: '名称',
    align:"center",
    dataIndex: 'name'
   },
  {
    title: '层级',
    align:"center",
    dataIndex: 'level'
   },
  {
    title: '父编码',
    align:"center",
    dataIndex: 'pcode'
   },
  {
    title: '物料/产品',
    align:"center",
    dataIndex: 'itemOrProduct',
    customRender:({text})=>{
      return render.renderDict(text,'item_or_product')
    }
   },
  {
    title: '数量',
    align:"center",
    dataIndex: 'quantity'
   },
  {
    title:'单位',
    align:'center',
    dataIndex:'unitOfMeasure',
    customRender:({text}) =>{
      return render.renderDict(text, 'unit_of_measure');
    }
  },
  {
    title: '规格型号',
    align:"center",
    dataIndex: 'specification'
   },
  {
    title: '结果信息',
    align:"center",
    dataIndex: 'status',
    fixed:'right',
    customRender:({record,text})=>{
      const tagTxt = !record.result||record.result=='success'?'成功':text
      const tagColor = !record.result||record.result=='success'?'green':'red'
      return render.renderTag(tagTxt,tagColor)
    }
  }
]
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '所属项目',
    field: 'wmProjectId',
    component: 'ApiSelect',
    componentProps: {
      api: projectList,
      labelField: 'name',
      valueField: 'id',
      params:{pageNo:1,pageSize:9999},
      resultField:'records'
    },
  },
  {
    label: '合同名称',
    field: 'name',
    component: 'Input'
  },
  {
    label: '合同编码',
    field: 'code',
    component: 'Input',
  },
  {
    label: '部门',
    field: 'sysOrgCode',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/sys/sysDepart/listAll',params:{isBu:'Y'} }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'departName',
      //值字段
      valueField: 'orgCode',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'result',
    },
  },
];

export const projInnerSearchCols:FormSchema[]=[
  {
    label: '名称',
    field: 'name',
    component: 'Input'
  },
  {
    label: '编码',
    field: 'code',
    component: 'Input',
  }
]

export const deptFormSchema: FormSchema[] = [
  {
    label: '所属项目',
    field: 'wmProjectId',
    component: 'ApiSelect',
    componentProps: {
      api: projectList,
      labelField: 'name',
      valueField: 'id',
      params:{pageNo:1,pageSize:9999},
      resultField:'records'
    },
  },
  {
    label: '合同名称',
    field: 'name',
    component: 'Input'
  },
  {
    label: '合同编码',
    field: 'code',
    component: 'Input',
  },
];


//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '所属项目',
    field: 'wmProjectId',
    component: 'ApiSelect',
    dynamicRules: ({model,schema}) => {
        return [
               { required: true, message: '必选!'},
        ];
    },
    componentProps: {
      api: projectList,
      labelField: 'name',
      valueField: 'id',
      params:{pageNo:1,pageSize:9999},
      resultField:'records'
    },
  },
  {
    label: '合同名称',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入合同名称!'},
          ];
     },
  },
  {
    label: '乙方',
    field: 'wmVendorId',
    component: 'ApiSelect',
    dynamicRules: ({model,schema}) => {
        return [
               { required: true, message: '必选!'},
        ];
    },
    componentProps: {
      //multiple: 多选；不填写为单选
      // mode: 'multiple',
      api: () => defHttp.get({url: '/wmhb/wmVendor/list'}),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'cnName',
      //值字段
      valueField: 'id',
      //请求参数
      params: {pageNo:1,pageSize:99999},
      //返回结果字段
      resultField: 'records',
    }
  },
  {
    label: '乙方合同编号',
    field: 'code',
    component: 'Input',
    required:true
  },
  {
    label: '负责人',
    field: 'chargeBy',
    component: 'UserSelect',
    componentProps: {
      //是否多选
      multi: false,
      //从用户表中选择一列，其值作为该控件的存储值，默认id列
      store: 'id',
      //是否排除我自己(当前登录用户)
      izExcludeMy: false,
      //是否禁用
      disabled: false,
    },
  },
  {
    label: '合同签订时间',
    field: 'signDate',
    component: 'DatePicker',
    defaultValue:dayjs(new Date()).format('YYYY-MM-DD'),
    componentProps: {
       showToday:true,
       //日期格式化，页面上显示的值
       format:'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD'
    },
  },
  {
    label: '合同类型',
    field: 'type',
    component: 'JDictSelectTag',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入项目类型!'},
          ];
     },
    componentProps:{
      dictCode:"contract_type"
    }
  },
  // {
  //   label: '进度权重',
  //   field: 'weight',
  //   component: 'Input'
  // },
  {
    label: '联系电话',
    field: 'phone',
    component: 'Input',
  },
  {
    label: '计划开始日期',
    field: 'planBeginTime',
    component: 'DatePicker',
    defaultValue:dayjs(new Date()).format('YYYY-MM-DD'),
    required:true,
    componentProps: {
       showToday:true,
       //日期格式化，页面上显示的值
       format:'YYYY-MM-DD',
       valueFormat: 'YYYY-MM-DD'
     },
  },
  {
    label: '计划完成日期',
    field: 'planEndTime',
    component: 'DatePicker',
    required:true,
    componentProps: {
       showToday:true,
       //日期格式化，页面上显示的值
       format:'YYYY-MM-DD',
       valueFormat: 'YYYY-MM-DD'
     },
  },

  {
    label:'不含税金额',
    field:'noTaxMoney',
    component:'Input'
  },
  {
    label:'税额',
    field:'tax',
    component:'Input'
  },
  {
    label:'单价',
    field:'price',
    component:'Input'
  },
  {
    label:'合计金额',
    field:'money',
    component:'Input'
  },
  {
    label: '附件(多选)',
    field: 'file',
    component: 'JUpload',
    componentProps:{
     },
  },
  {
    label: '甲方',
    field: 'wmClientId',
    component: 'ApiSelect',
    dynamicRules: ({model,schema}) => {
        return [
               { required: true, message: '必选!'},
        ];
    },
    componentProps: {
      api: clientList,
      labelField: 'cnName',
      valueField: 'id',
      params:{pageNo:1,pageSize:99999},
      resultField:'records'
    },
  },
  {
    label:'甲方合同编号',
    field:'clientContractNo',
    component:'Input',
    required:false
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];


export const contractBomForm: FormSchema[] = [
  {
    label: '合同名称',
    field: 'wmContractName',
    component: 'Input',
    componentProps:{
      disabled: true
    }
  },
  {
    label: '合同编号',
    field: 'wmContractId',
    component: 'Input',
    componentProps:{
      disabled: true
    }
  },
  {
    label:'层级',
    field:'level',
    component:'InputNumber',
    componentProps:{
      disabled: true
    }
  },
  {
    label:'父产品',
    field:'parentName',
    component:'Input',
    componentProps:{
      disabled: true
    },
    ifShow:({ values })=>{
      return !!values.parentName
    }
  },
  {
    label:'产品名称',
    field:'name',
    component:'Input',
    required:true
  },
  {
    label: '产品性质',
    field: 'taskType',
    defaultValue: "SELF",
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"task_type"
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入任务类型!'},
          ];
     },
  },
  {
    label:'编码',
    field:'code',
    component:'Input',
    required:true
  },
  {
    label:'数量',
    field:'quantity',
    component:'InputNumber',
    required:true
  },
  {
    label:'产品物料标识',
    field:'itemOrProduct',
    component:'JDictSelectTag',
    required:true,
    defaultValue:'PRODUCT',
    componentProps:{
      dictCode:'item_or_product'
    }
  },
  {
    label: '规格型号',
    field: 'specification',
    component: 'Input'
  },
  {
    label: '尺寸',
    field: 'size',
    component: 'Input'
  },
  {
    label: '单位',
    field: 'unitOfMeasure',
    component: 'JSearchSelect',
    componentProps:{
        dict:"unit_of_measure"
     },
  },
  {
    label: '父编码',
    field: 'pid',
    component: 'Input',
    defaultValue:'0',
    show:false
  },
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '合同名称',order: 1,view: 'text', type: 'string',},
  code: {title: '乙方合同编号',order: 2,view: 'text', type: 'string',},
  clientContractNo: {title: '甲方合同编号',order: 2,view: 'text', type: 'string',},
  chargeBy: {title: '负责人',order: 3,view: 'list', type: 'string',dictCode: '',},
  wmClientId_dictText: {title: '甲方单位',order: 3,view: 'text', type: 'string'},
  wmVendorId_dictText: {title: '乙方单位',order: 3,view: 'text', type: 'string'},
  signDate: {title: '合同签订时间',order: 4,view: 'date', type: 'string',},
  type: {title: '合同类型',order: 5,view: 'text', type: 'string',},
  //weight: {title: '进度权重',order: 6,view: 'text', type: 'string',},
  phone: {title: '联系电话',order: 7,view: 'text', type: 'string',},
  progress: {title: '进度',order: 8,view: 'text', type: 'string',},
  status: {title: '状态',order: 9,view: 'list', type: 'string',dictCode: 'contract_status',},
  planBeginTime: {title: '计划开始时间',order: 10,view: 'datetime', type: 'string',},
  planEndTime: {title: '计划完成时间',order: 11,view: 'datetime', type: 'string',},
  factBeginTime: {title: '实际开始时间',order: 12,view: 'datetime', type: 'string',},
  factEndTime: {title: '实际完成时间',order: 13,view: 'datetime', type: 'string',},
  remark: {title: '备注',order: 16,view: 'textarea', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
